package com.hxs.learn.entity.core;

import java.util.Date;
import java.util.UUID;

import org.apache.ibatis.type.Alias;
import org.apache.shiro.authc.AuthenticationToken;

import org.springframework.util.DigestUtils;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldStrategy;
import com.baomidou.mybatisplus.enums.IdType;

import com.fasterxml.jackson.annotation.JsonFormat;

import com.hxs.learn.common.entity.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author huxinsheng
 * @date 2018-04-24 15:32:13
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "sys_user")
@Alias(value = "SysUser")
public class SysUser implements BaseEntity, AuthenticationToken {

    /**
     * 编号
     */
    @TableId(
            value = "id",
            type = IdType.INPUT
    )
    private String id;

    /**
     * 数据级别 0正常 1审核中 2禁用 -1已删除
     */
    @TableField(value = "status")
    private Integer status;

    /**
     * 创建人
     */
    @TableField(
            value = "creator",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String creator;

    /**
     * 部门名称
     */
    @TableField(exist = false)
    private String departmentName;
    /**
     * 登录名
     */
    @TableField(
            value = "loginName",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String loginName;

    /**
     * 手机号码 用来做账号鉴权
     */
    @TableField(
            value = "mobile",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String mobile;

    /**
     * 登录密码
     */
    @TableField(
            value = "password",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String password;

    /**
     * 真实姓名
     */
    @TableField(
            value = "realName",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String realName;

    /**
     * 更新人
     */
    @TableField(
            value = "updateBy",
            strategy = FieldStrategy.NOT_EMPTY
    )
    private String updateBy;

    /**
     * 创建日期
     */
    @TableField(value = "createTime")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    private Date createTime;

    /**
     * 更新日期
     */
    @TableField(value = "updateTime")
    @JsonFormat(
            pattern = "yyyy-MM-dd HH:mm:ss",
            timezone = "GMT+8"
    )
    private Date updateTime;

    @TableField(exist = false)
    private String newPwd;

    public static String newId() {
        return DigestUtils.md5DigestAsHex(UUID.randomUUID().toString().getBytes());
    }

    /**
     * 返回密码
     */
    @Override
    public Object getCredentials() {
        return this.getPassword();
    }

    /**
     * 返回用户名
     */
    @Override
    public Object getPrincipal() {
        return this.getLoginName();
    }


}


//~ Formatted by Jindent --- http://www.jindent.com
